/**
 * @(#)MomoUserServiceImpl.java 2018年4月3日
 * Copyright(C) 2018年4月3日 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.service.impl;


import java.util.Date;

import javax.annotation.Resource;

import org.jsbd.boss.dao.IMomoUserDao;
import org.jsbd.boss.domian.channel.MomoUser;
import org.jsbd.boss.domian.channel.UserClientInfo;
import org.jsbd.boss.service.IMomoUserService;
import org.jsbd.boss.service.IUserClientInfoService;
import org.jsbd.boss.util.BeanCopierUtil;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.common.utils.StringUtils;


/**
 * 陌陌用户service实现类
 * @author <a href="mailto:zhouchao@zhexinit.com" >周超</a>
 * @version 1.0.0
 */
@Service("momoUserService")
public class MomoUserServiceImpl implements IMomoUserService {
	public static final Logger LOGGER = LoggerFactory.getLogger(MomoUserServiceImpl.class);

	@Resource
	private IUserClientInfoService userClientInfoService;
	@Resource
	private IMomoUserDao momoUserDao;
	
	@Override
	public boolean saveMomoUser(MomoUser user) {
		String mark=user.getMark();
		Integer provinceId=user.getProvince();
		if(provinceId==null){
			provinceId=-1;
		}
		UserClientInfo clientInfo = userClientInfoService.selectClientInfo(user.getImsi(), provinceId);
		if(clientInfo==null){
			LOGGER.warn("陌陌账号获取不到用户信息 imsi[{}],province[{}]",user.getImsi(),provinceId);
			return false;
		}
		
		BeanCopierUtil.UserClientInfo2MomoUserBeanCopier.copy(clientInfo, user, null);
		
		if (user.getCity() == null) {
			user.setCity(-1);
		}
		if(StringUtils.isBlank(user.getRd())){
			user.setRd(DateUtil.getCurrentDateStr());
		}
		user.setMark(mark);
		user.setCreateTime(new Date());
		return momoUserDao.saveMomoUser(user);
	}
}
